-
Notifications
You must be signed in to change notification settings - Fork 634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(flamegraph): added sub-second units support for trace visualization #1418
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1418 +/- ##
==========================================
+ Coverage 68.49% 68.56% +0.07%
==========================================
Files 129 129
Lines 4246 4255 +9
Branches 1136 1139 +3
==========================================
+ Hits 2908 2917 +9
Misses 1333 1333
Partials 5 5
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
size-limit report 📦
|
expect(df.format(100, 100)).toBe('1.00 second'); | ||
expect(df.format(2000, 100)).toBe('20.00 seconds'); | ||
expect(df.format(2012.3, 100)).toBe('20.12 seconds'); | ||
expect(df.format(2012.3, 100)).toBe('20123.00 ms'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite get this, why do we use seconds
for 2000
, but ms
for 2012.3
?
@@ -1,5 +1,6 @@ | |||
/* eslint-disable max-classes-per-file */ | |||
import { Units } from '@pyroscope/models/src'; | |||
import _last from 'lodash/last'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I'm also not a big fan of these — there's value in keeping the list of dependencies as low as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, this will be removed
[60, 'minute'], | ||
[60, 'hour'], | ||
[24, 'day'], | ||
[30, 'month'], | ||
[12, 'year'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for completion it's worth adding tests for these
expect(df.format(8000, 100)).toBe('80.00 seconds'); | ||
expect(df.format(374.12, 100)).toBe('3741200.00 μs'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one also doesn't seem right
|
||
units = ''; | ||
|
||
constructor(maxDur: number, units?: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
units
isn't really used by any of the users of SubSecondDurationFormatter
, right? Therefore I'd remove it altogether.
format(samples: number, sampleRate: number): string { | ||
let n = samples / sampleRate / this.divider; | ||
|
||
if (n && !Number.isInteger(n) && this.divider === 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is hard to understand, and it is faulty (see test cases above). I would not invest any more time into it.
I think you could use existing DurationFormatter
, but modify it in two ways:
- Add milliseconds and microseconds to
durations
array, with1000
multipliers each. - Modify line 138 to be
let n = samples / sampleRate * 1000000 / this.divider
to compensate for extra precision.
And the rest of it should work just fine.
@StasDachinsky let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And by the way, if that's the case (and these are the only changes we're making to this formatter) we probably don't need a separate class and instead we could have a constructor argument in the existing DurationFormatter
.
/cc @Rperry2174 — let us know if there's more changes that need to happen. E.g jaeger does double numbers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will update the code according to your recommendations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@petethepig Can you please explain what you mean by the constructor argument for DurationFormatter
? Should I keep the current logic when the suffix is selected by the constructor argument maxDur
, or do I need to update it to allow DurationFormatter
to select the suffix based on the value passed in the format function (like in the jaeger
), but only for trase_samples
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@StasDachinsky by that I meant that we'd add a new argument to DurationFormatter
constructor, something like enableSubsecondPrecision
, and then if you want to include sub-second precision you'd call it with that extra boolean, e.g:
new DurationFormatter(123, '', true)
This way we can make it so that in all other cases DurationFormatter
is still working the same way it used to (with no sub-second precision) and it only does work with sub-second precision in tracing mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It all looks good, I think the last thing we need to do is make it so that sub second duration only show up for trace_samples
. That will also fix the cypress test.
7f62082
to
0ff3738
Compare
0ff3738
to
5362965
Compare
Brief
Changes
Concerns